//
//  QBWordsCell.m
//  QiuBai
//
//  Created by yaohongchao on 5/1/16.
//  Copyright © 2016 yaohongchao. All rights reserved.
//

#import "QBWordsCell.h"
#import "QBUserInfoView.h"
#import "QBVoteView.h"
#import "QBWordsContent.h"

@interface QBWordsCell()
@property(nonatomic,weak)UILabel *lblContent;
@property(nonatomic,weak)QBUserInfoView *userView;
@property(nonatomic,weak)QBVoteView *voteView;
@property(nonatomic,weak)QBWordsContent *wordsContentView;

@end

@implementation QBWordsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self setui];
    }
    return self;
}

-(void)setui{
    self.dk_backgroundColorPicker = DKColorPickerWithKey(BG);
    
    QBUserInfoView *userView = [[QBUserInfoView alloc]init];
    userView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:userView];
    self.userView = userView;
    userView.dk_backgroundColorPicker = DKColorPickerWithKey(CellBg);
    userView.dk_tintColorPicker = DKColorPickerWithKey(CellSelectedBg);
    
    QBWordsContent *wordsContentView = [[QBWordsContent alloc]init];
    wordsContentView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:wordsContentView];
    self.wordsContentView = wordsContentView;
    wordsContentView.dk_backgroundColorPicker = DKColorPickerWithKey(CellBg);
    wordsContentView.dk_tintColorPicker = DKColorPickerWithKey(CellSelectedBg);
    
    QBVoteView *voteView = [[QBVoteView alloc]init];
    voteView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:voteView];
    self.voteView = voteView;
    voteView.dk_backgroundColorPicker = DKColorPickerWithKey(CellBg);
    voteView.dk_tintColorPicker = DKColorPickerWithKey(CellSelectedBg);
    //设置约束
    [self makeConstraint];
}

-(void)makeConstraint{
    WS(weakSelf);
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(65);
    }];
    [self.wordsContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.contentView);
        make.top.mas_equalTo(weakSelf.userView.mas_bottom);
        make.bottom.mas_equalTo(weakSelf.voteView.mas_top);
    }];
    [self.voteView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(weakSelf.contentView);
        make.bottom.equalTo(weakSelf.contentView).offset(-kMargin);
        make.height.mas_equalTo(90);
    }];
}

-(void)setItem:(Item *)item{
    _item = item;
    item.votes.comment = item.comments_count;
    self.userView.item = item;
    self.voteView.vote = item.votes;
    self.wordsContentView.item = item;
}

@end
